extends Camera3D

var _looking := false

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	var dir := Input.get_vector(&"left", &"right", &"forward", &"back")
	var y := Input.get_axis(&"down", &"up")
	var fwd = Vector3(basis.z.x, 0, basis.z.z).normalized()
	var right = Vector3(basis.x.x, 0, basis.x.z).normalized()
	position += 10 * delta * (dir.x * right + dir.y * fwd + y * Vector3.UP)
	
	pass


func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT:
			_looking = event.pressed
	
	if _looking and event is InputEventMouseMotion:
		global_rotation += 0.01 * Vector3(-event.relative.y, -event.relative.x, 0.0)
